# file:: account.rb
# author::  Ralph M. Churchill
# version::
# date::
#
# This source code copyright (C) 2006 by Ralph M. Churchill
# All rights reserved.
#
# Released under the terms of the GNU General Public License
# See LICENSE file for additional information.

require 'models/entity'
require 'models/container'

class Account < Entity
    include HasManyCharacters

    properties :password,:login_time,:rank,:allowed_accounts,:logged_in

    def initialize
        self.allowed_accounts = 3
        self.rank = 1
        self.logged_in = false
        super
    end

    def Account.acceptable_name?(name)
        raise "Name cannot be blank." if name.empty?
        raise "Name can only contain letters and underscores." if name =~ /\W|\d/
        raise "Name must be at least 3 characters long." if name.length < 3
        raise "Name cannot start with an underscore." if name =~ /^_/
        name
    end
    def Account.acceptable_password?(passwd)
        raise "Password cannot be blank." if passwd.empty?
        passwd
    end
    def Account.create(opts)
        raise "Name and password required!" unless opts.key?(:name) and opts.key?(:password)
        a = Account.new
        a.name = opts[:name]
        a.password = opts[:password]
        a
    end
end

